package com.yidian.controller;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author whb
 * @create 2021-07-26 10:28
 * @desciption 用户登录控制类
 */
@RestController
@RequestMapping("/login")
public class LoginController  {
    /**
     * 获取登录用户名
     * @return
     */
    @RequestMapping("/username")
    public Map username(){
        String username = SecurityContextHolder.getContext().getAuthentication().getName();//获取登录用户名
        //未登录时，通过CAS获取到的用户名
        if ("anonymousUser".equals(username)){
            username="";
        }
        Map map = new HashMap();
        map.put("username",username);
        return map;
    }
}
